package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.*;

public class BankApplication {

	public static void main(String[] args) {

		Bank bank1 = new Bank("Alfa-bank");

		fillInBank(bank1);
		printBalance(bank1);
		modifyBank(bank1);
		printBalance(bank1);
		new BankService().printMaximumAmountToWithdraw(bank1);
	}

	static void printBalance(Bank b) {
		Client[] clients = b.getClients();
		System.out.println("Bank " + b + " balance:");
		for (int i = 0; i < clients.length; i++) {
			if (clients[i] != null) {
				System.out.println(clients[i].getClientSalutation()
						+ clients[i].getClientBalance());
			}
		}
	}

	static void fillInBank(Bank bank) {
		Account account1 = new SavingAccount(100.0);
		Account account2 = new CheckingAccount(40.0, 50.0);
		Client client1 = new Client(Gender.MALE, "Jons", account1);
		Client client2 = new Client(Gender.FEMALE, "Mary", account2);
		BankService bs = new BankService();
		bs.addClient(bank, client1);
		bs.addClient(bank, client2);
	}

	static void modifyBank(Bank bank) {
		Client client1 = bank.getClients()[0];
		Client client2 = bank.getClients()[1];

		Account account1 = client1.getAccount();
		Account account2 = client2.getAccount();

		account2.withdraw(45);
		account1.deposit(45);
		System.out.println("=== transaction 45 is made === ");
	}
}
